package top.itpath.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import top.itpath.admin.intercepter.PermissionInterceptor;

import javax.annotation.PostConstruct;

/**
 * @author zhaomengru
 * create by  2023/10/10 - 11:24
 */
@Slf4j
@AutoConfiguration
@ConditionalOnMissingBean({AutoConfiguration.class})
@AutoConfigureAfter({HibernateJpaAutoConfiguration.class})
@ComponentScan(basePackages = {"top.itpath"})
public class AdminApplicationConfig {

    @PostConstruct
    public void init() {
        log.info("init admin app...");
    }

    @Bean
    public WebMvcConfigurer webMvcConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                registry.addInterceptor(new PermissionInterceptor());
            }
        };
    }
}

